package com.example.rwq_test.niuke.stack;

import java.util.Stack;

/**
 * TODO note
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2023/11/27
 */
public class MinStack {
    private static Stack<Integer> stack = new Stack<>();
    private static Stack<Integer> min = new Stack<>();

    public static void push(int value) {
        stack.push(value);
        if (min.isEmpty() || value <= min.peek()) {
            min.push(value);
        }
    }

    public static Integer pop() {
        int val = stack.pop();
        if (min.peek() == val) {
            min.pop();
        }
        return val;
    }

    public static Integer top() {
        return stack.peek();
    }

    public static Integer min() {
        return min.peek();
    }
}
